<html>
<head><meta charset="utf-8"><title>Add &quot;add reference&quot; code action/diagnostics · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html">Add &quot;add reference&quot; code action/diagnostics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219703464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219703464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219703464">(Dec 12 2020 at 11:09)</a>:</h4>
<p>Hi. What are the shortcomings of current type system implementation in <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics/expr.rs#L156-L160">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics/expr.rs#L156-L160</a>? I think that's a blocking FIXME for <a href="https://github.com/rust-analyzer/rust-analyzer/issues/6814">https://github.com/rust-analyzer/rust-analyzer/issues/6814</a></p>



<a name="219708278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219708278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219708278">(Dec 12 2020 at 13:11)</a>:</h4>
<p>Pretty much everything under <a href="https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AA-ty">https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AA-ty</a></p>



<a name="219708343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219708343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219708343">(Dec 12 2020 at 13:12)</a>:</h4>
<p>Type inference works mostly fine if you're not doing anything too fancy trait-wise, but it's annoying to have false positives for warning/error diagnostics, so the idea is to avoid that</p>



<a name="219709923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219709923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219709923">(Dec 12 2020 at 13:53)</a>:</h4>
<p>you can run <code>rust-analyzer analysis-stats -v .</code> in some project (that presumably type-checks) to see examples</p>



<a name="219709977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219709977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219709977">(Dec 12 2020 at 13:55)</a>:</h4>
<p>I don't think that blocks 6814 though, we just should only emit the diagnostic if we have a quickfix. If we have a type mismatch and adding the reference seems to fix the type mismatch, I'd say it's pretty unlikely to be a false positive</p>



<a name="219710034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219710034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219710034">(Dec 12 2020 at 13:57)</a>:</h4>
<p>hmm looking at the type mismatches in RA right now, it seems our main problem is some kind of problem with coercion to <code>dyn Trait</code>... I wonder if I looked into that before <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="219960051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219960051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219960051">(Dec 15 2020 at 10:31)</a>:</h4>
<p>Is it ok to promote <code>once-cell</code> from <code>dev-dependencies</code> to <code>dependencies</code>? Since <code>iter</code> method of <code>ArenaMap</code> doesn't have <code>ExactSizeIterator</code> I can't find any way to get if we have type mismatches without calling <code>iter</code> twice</p>



<a name="219960072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219960072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219960072">(Dec 15 2020 at 10:31)</a>:</h4>
<p>Related: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/6853#discussion_r543212866">https://github.com/rust-analyzer/rust-analyzer/pull/6853#discussion_r543212866</a></p>



<a name="219960089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219960089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219960089">(Dec 15 2020 at 10:31)</a>:</h4>
<p>yup, it should be fine</p>



<a name="219960190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219960190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219960190">(Dec 15 2020 at 10:32)</a>:</h4>
<p>Ok, thanks!</p>



<a name="219962683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219962683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219962683">(Dec 15 2020 at 10:58)</a>:</h4>
<p>hmm, is there some borrow checking issue there? otherwise it should be completely fine to call <code>body_with_source_map</code> inside the <code>filter_map</code>, it'll be very fast and presumably there won't be many calls anyway</p>



<a name="219962802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219962802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219962802">(Dec 15 2020 at 10:59)</a>:</h4>
<p>If you are asking about those 3 references above whole iterator logic - yep, borrowck is angry about borrowing <code>self</code> instead of it's fields</p>



<a name="219962931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219962931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219962931">(Dec 15 2020 at 11:00)</a>:</h4>
<p>Moving <code>body_with_source_map</code> to <code>filter_map</code> would only remove <code>owner</code>, while leaving <code>infer</code> and <code>sink</code> intact</p>



<a name="219964108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219964108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219964108">(Dec 15 2020 at 11:12)</a>:</h4>
<p>I'm asking about the use of <code>Lazy</code></p>



<a name="219967125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Add%20%22add%20reference%22%20code%20action/diagnostics/near/219967125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Add.20.22add.20reference.22.20code.20action.2Fdiagnostics.html#219967125">(Dec 15 2020 at 11:44)</a>:</h4>
<p>Hmm. Removing <code>Lazy</code> still leaves us with <code>owner</code> because  of borrowck, but I can return <code>once-cell</code> back to <code>dev-dependencies</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>